package com.exposit.books.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.exposit.books.dao.BookDAO;
import com.exposit.books.domain.Author;
import com.exposit.books.domain.Book;

@Service
@Transactional
public class IncomeServiceImpl implements IncomeService {
	@Autowired
	private BookDAO bookDAO;
	@Override
	public Long getIncomeById(Long Id) {
		// TODO Auto-generated method stub
		Long income = 0L;
		Book book = bookDAO.getById(Id);
		Author author = book.getAuthor();
		Long p_price = book.getPurchasePrice();
		Long payments = author.getPayments();
		Long percentage = author.getPercentage();
		if (payments!=0){
			income = p_price - payments;
		}
		else income = p_price*percentage/100;
		return income;
	}
	@Override
	public Book getBookById(Long id) {
		// TODO Auto-generated method stub
		return bookDAO.getById(id);
	}


}
